import axios from 'axios';
import nProgress from 'nprogress';
import 'nprogress/nprogress.css';
import store from '@/store';

const service = axios.create({
        baseURL: '/api/v2',
        timeout: 5000
    });

        //请求拦截
    service.interceptors.request.use((config) => {
        nProgress.start();
        let userTempId = store.state.user.userTempId;
        // console.log('userTemp',userTempId);
        if(userTempId) {
        config.headers.userTempId = userTempId;
        }
         let token = store.state.user.token;
        // console.log('userTemp',userTempId);
        if(token) {
        config.headers.token = token;
        }
        return config
    }, (err) => { 
    })
    //响应拦截
    service.interceptors.response.use((res) => {
        nProgress.done();   
        return res.data    
    }, (err) => {
        nProgress.done();   
        return new Promise((params) => {
            
        })
    })

    export default service